"""
Copyright (C) 2008 Masahiro Nakao

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
"""

import random

class Random_org:
    def __init__(self, seed):
        random.seed(seed)
        self.number_of_rand_function = 0
        self.seek = 0
    
    def normalvariate(self, average, var):
        self.number_of_rand_function += 1
        return random.normalvariate(average, var)

    # Output Average = 0.00, Var = 2.56
    def test_normalvariate(self):
        f = open("./normalvariate_ave_0_var_2.56.txt", "r")
        value = 0
        for index, line in enumerate(f):
            if index == self.seek:
                value = line
                self.seek += 1
                break
        f.close()
        
        return float(value)
    
    def uniform(self, min, max):
        self.number_of_rand_function += 1
        return random.uniform(min, max)
    
    def test_uniform(self):
        f = open("./uniform_5.12--5.12.txt", "r")
        value = 0
        for index, line in enumerate(f):
            if index == self.seek:
                value = line
                self.seek += 1
                break
        f.close()
        
        return float(value)
        
    def get_random(self):
        self.number_of_rand_function += 1
        return random.random()
    
    # Output 0.00 <= x <= 1.00
    def test_get_random(self):
        f = open("./random_0-1.txt", "r")
        value = 0
        for index, line in enumerate(f):
            if index == self.seek:
                value = line
                self.seek += 1
                break
        f.close()
        
        return float(value)
    
    def get_number_of_rand_function(self):
        return self.number_of_rand_function

r = Random_org(2)
#f = open("./uniform_5.12--5.12.txt", "w")
#for i in range(10000):
#    f.write(str(round(r.uniform(-5.12, 5.12),2)) + "\n")